package com.digitaldreamers.framework.scene.layer;

import org.andengine.entity.scene.CameraScene;

public abstract class ManagedLayer extends CameraScene {
	protected boolean mIsLoaded;
	protected boolean mIsUnloadOnHidden;
	
	public ManagedLayer() {
		this(false);
	}
	
	public ManagedLayer(boolean pIsUnloadOnHidden) {
		mIsLoaded = false;
		mIsUnloadOnHidden = pIsUnloadOnHidden;
		setBackgroundEnabled(false);
	}
	
	public void onShowManagedLayer() {
		if(!mIsLoaded) {
			mIsLoaded = true;
			onLoadLayer();
		}
		setIgnoreUpdate(false);
		onShowLayer();
	}
	
	public void onHideManagedLayer() {
		setIgnoreUpdate(true);
		onHideLayer();
		if(mIsUnloadOnHidden) {
			onUnloadLayer();
		}
	}
	
	public abstract void onLoadLayer();
	public abstract void onShowLayer();
	public abstract void onHideLayer();
	public abstract void onUnloadLayer();
}